<template>
  <div class="container">
    <div class="breadcrumb-container">
      <a-breadcrumb separator=">">
        <a-breadcrumb-item>
          <NuxtLink to="/" class="more"> 首页</NuxtLink>
        </a-breadcrumb-item>
        <a-breadcrumb-item>
          <NuxtLink
            :to="`/classify?classifyId=${movieInfo?.category[0].id}`"
            class="more"
          >
            {{ movieInfo?.category[0].name }}
          </NuxtLink>
        </a-breadcrumb-item>
        <a-breadcrumb-item>{{ movieInfo?.name }}</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <div class="detail-box">
      <div class="book-cover-box">
        <img
          :alt="movieInfo?.name"
          fetchpriority="high"
          class="film_bookCover__YRcsa"
          :src="movieInfo?.cover"
          style="color: transparent"
        />
      </div>
      <h1 class="book-name">{{ movieInfo?.name }}</h1>
      <p class="chapter-count">99 集</p>
      <p class="intro">{{ movieInfo?.introduction }}</p>
      <div class="tag-box">
        <NuxtLink
          class="tag-item"
          :to="`/classify?classifyId=${category.id}`"
          v-for="category in movieInfo?.category"
          :key="category.id"
          >{{ category.name }}</NuxtLink
        >
      </div>
      <a-row class="play-btn-box">
        <a-col :span="6" :lg="8" :md="24" :sm="24" :xs="24">
          <NuxtLink class="play-btn" :to="`/play/${movieInfo?.id}`">
            <CaretRightOutlined style="font-size: 0.23rem" />
            立即播放
          </NuxtLink>
        </a-col>
        <a-col :span="18" :lg="16" :md="24" :sm="0" :xs="0">
          <a-flex align="center" class="share-box">
            <div class="share-label">分享：</div>
            <img :src="facebook" alt="twitter" />
            <img :src="twitter" alt="twitter" />
            <img :src="instagram" alt="twitter" />
            <a-tooltip placement="top">
              <template #title>
                <span>点击复制链接</span>
              </template>
              <img :src="copyIcon" alt="copyIcon" class="copyIcon" />
            </a-tooltip>
          </a-flex>
        </a-col>
      </a-row>
    </div>
    <a-row>
      <a-col :span="24" :xs="0" :sm="0" :md="24" :lg="24">
        <a-flex class="title-wrap" align="center">
          <h2>剧集列表</h2>
          <div class="counts">({{ episodeState.data.length }} 集)</div>
        </a-flex>
        <a-row class="list-info" :gutter="10">
          <a-col
            :span="4"
            :md="8"
            :lg="6"
            :xl="6"
            :xxl="4"
            v-for="(item, index) in isSeeMore
              ? [...currentPageData].splice(0, 11)
              : currentPageData"
            :key="item.id"
          >
            <NuxtLink :to="`/play/${movieInfo?.id}?episodeId=${item.id}`">
              <a-flex class="list-item">
                <div class="img-box">
                  <img :alt="item.name" :src="item.cover" />
                </div>
                <div class="intro">
                  <div class="title">{{ movieInfo?.name }}</div>
                  <div class="page-num">{{ item.name }}</div>
                </div>
              </a-flex>
            </NuxtLink>
          </a-col>
          <a-col
            :span="4"
            :md="8"
            :lg="6"
            :xl="6"
            :xxl="4"
            v-if="isSeeMore"
            @click="isSeeMore = false"
          >
            <a-flex justify="center" align="center" class="see-more">
              <span>查看更多</span>
              <DownCircleFilled />
            </a-flex>
          </a-col>
        </a-row>
        <a-flex
          class="tab-box"
          v-if="!isSeeMore"
          align="center"
          justify="center"
        >
          <div
            v-for="page in totalPages"
            :key="page"
            class="tab-item"
            :class="{ 'tab-item-activ': episodeState.currentPage === page }"
            @click="changePage(page)"
          >
            {{ (page - 1) * episodeState.pageSize + 1 }} -
            {{
              Math.min(page * episodeState.pageSize, episodeState.data.length)
            }}
          </div>
        </a-flex>
      </a-col>
    </a-row>
  </div>
  <a-row>
    <a-col :xs="24" :sm="24" :md="0">
      <div class="h5-intro-box">
        <div class="intro-title">简介</div>
        <p class="intro">
          {{ movieInfo?.introduction }}
        </p>
      </div>
      <div class="episode-nav">
        <div class="catalog-box">
          <p>
            剧集列表<span>({{ movieInfo?.episodeCount ?? 0 }} 集)</span>
          </p>
          <RightOutlined />
        </div>
        <a-flex align="center" class="share-box">
          <div class="share-label">分享：</div>
          <img :src="facebook" alt="twitter" />
          <img :src="twitter" alt="twitter" />
          <img :src="instagram" alt="twitter" />
          <a-tooltip placement="top">
            <template #title>
              <span>点击复制链接</span>
            </template>
            <img :src="copyIcon" alt="copyIcon" class="copyIcon" />
          </a-tooltip>
        </a-flex>
      </div>
    </a-col>
  </a-row>
  <div class="container">
    <a-flex class="title-wrap" justify="space-between">
      <h2>猜你喜欢</h2>
    </a-flex>
    <a-row class="episode-list" :gutter="10">
      <a-col
        :span="4"
        :xs="8"
        :md="8"
        :lg="4"
        class="book-item"
        v-for="(item, index) in recommendedMovies"
        :key="index"
      >
        <NuxtLink :to="`/movie/${item.id}`" class="book-image">
          <img :alt="item.name" loading="lazy" :src="item.cover" />
          <div class="chapter-count">{{ item.episodeCount ?? 0 }} 集</div>
        </NuxtLink>
        <div class="book-name">{{ item.name }}</div>
        <div class="book-name-box">
          <div class="book-name-hover">{{ item.name }}</div>
          <div class="tag-box">
            <NuxtLink
              class="tag-item"
              :to="`/movie/${item.id}`"
              v-for="(category, index) in item?.category"
              :key="index"
            >
              {{ category }}
            </NuxtLink>
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script setup lang="ts">
import {
  CaretRightOutlined,
  DownCircleFilled,
  RightOutlined,
} from "@ant-design/icons-vue"
import {
  twitter,
  instagram,
  facebook,
  copyIcon,
} from "@/assets/images/base64.js"
import { request as getMovieInfoRequest } from "@/api/server/mods/movie/getMovieInfo"
import { request as getRecommendationsRequest } from "@/api/server/mods/movie/getRecommendations"
import { request as getMoviesEpisodeRequest } from "@/api/server/mods/moviesEpisode/getMoviesEpisode"

import { errorTips } from "@/utils"
interface MovieState extends defs.server.MovieEntity {
  episodeCount?: number
}
const isSeeMore = ref(true)
const $route = useRoute()
const movieInfo = ref<MovieState>()
const recommendedMovies = ref<MovieState[]>([])
onMounted(() => {
  getMovieInfo()
  getMoviesEpisode()
  getRecommendedMovies()
})
/** 获取电影详情 */
async function getMovieInfo() {
  try {
    const { data, success } = await getMovieInfoRequest(
      $route.params.id as string
    )
    if (success) {
      movieInfo.value = data
    }
  } catch (error: any) {
    errorTips(error.message)
  }
}
const episodeState = reactive({
  data: [] as defs.server.MoviesEpisodeEntity[],
  currentPage: 1,
  pageSize: 30,
})
const totalPages = computed(() =>
  Math.ceil(episodeState.data.length / episodeState.pageSize)
)
const currentPageData = computed(() => {
  const start = (episodeState.currentPage - 1) * episodeState.pageSize
  const end = start + episodeState.pageSize
  return episodeState.data.slice(start, end)
})
function changePage(page: number) {
  episodeState.currentPage = page
}
/** 获取电影剧集 */
async function getMoviesEpisode() {
  try {
    const { data, success } = await getMoviesEpisodeRequest(
      $route.params.id as string
    )
    if (success) {
      episodeState.data = data
    }
  } catch (error: any) {
    errorTips(error.message)
  }
}
/** 获取推荐电影 */
async function getRecommendedMovies() {
  try {
    const { data, success } = await getRecommendationsRequest(
      $route.params.id as string
    )
    if (success) {
      recommendedMovies.value = data
    }
  } catch (error: any) {
    errorTips(error.message)
  }
}
</script>
<style lang="scss" scoped>
.breadcrumb-container {
  height: 0.8rem;
  padding: 0 0.12rem;
  border-bottom: 1px solid #eaeaeb;
  background-color: transparent;
  display: flex;
  align-items: center;
  a {
    font-size: 0.18rem;
    line-height: 0.28rem;
  }
}
.detail-box {
  text-align: left;
  padding: 0.32rem 0.32rem 0.32rem 3.41rem;
  margin: 0.76rem 0 0.48rem;
  background: rgba(50, 50, 57, 0.07);
  border-radius: 0.08rem;
  height: 3.78rem;
  position: relative;
  .book-cover-box {
    position: absolute;
    left: 0.1rem;
    bottom: 0.1rem;
    z-index: 1;
    width: 3.15rem;
    height: 4.2rem;
    margin: 0;
    text-align: center;
    img {
      margin: 0;
      border-radius: 0.08rem;
      width: 3.15rem;
      height: 4.2rem;
      object-fit: cover;
    }
  }
  .book-name {
    text-align: left;
    display: block;
    width: 9rem;
    font-size: 0.24rem;
    line-height: 0.32rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-bottom: 0.08rem;
  }
  .chapter-count {
    font-size: 0.14rem;
    line-height: 0.2rem;
    color: rgba(0, 0, 0, 0.6);
    margin-bottom: 0.12rem;
  }
  .intro {
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 7;
    word-wrap: break-word;
    width: 100%;
    font-size: 0.14rem;
    line-height: 0.2rem;
    color: rgba(0, 0, 0, 0.6);
    margin-bottom: 0.12rem;
  }
  .tag-box {
    grid-gap: 0.08rem;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 0;
    .tag-item {
      border-radius: 1rem;
      padding: 0.04rem 0.1rem;
      font-size: 0.12rem;
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
      line-height: normal;
      font-weight: 400;
      color: rgba(0, 0, 0, 0.6);
      background-color: rgba(50, 50, 57, 0.07);
    }
  }
  .play-btn-box {
    width: 100%;
    height: 0.48rem;
    margin-bottom: 0;
    position: absolute;
    left: 3.41rem;
    bottom: 0.32rem;
    z-index: 1;
    @media (max-width: 992px) {
      bottom: 0.62rem;
      .share-box {
        margin-top: 0.08rem;
      }
    }
    .play-btn {
      width: 3.28rem;
      font-weight: 500;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: row;
      height: 0.48rem;
      background: linear-gradient(270deg, #ff871f, #ff0045 48%, #f40065);
      font-size: 0.18rem;
      color: #fff;
      border-radius: 0.08rem;
      min-width: auto;
      margin-right: 0.4rem;
      padding: 0 0.2rem;
    }
    .share-box {
      height: 0.4rem;
      .share-label {
        font-size: 0.18rem;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.9);
        margin-right: 0.2rem;
      }
      img {
        width: 0.4rem;
        height: 0.4rem;
        border-radius: 50%;
        margin-right: 0.1rem;
        cursor: pointer;
        transition: all 0.3s;
      }
      .copyIcon {
        filter: grayscale(1);
        &:hover {
          filter: grayscale(0);
        }
      }
    }
  }
}
.list-info {
  margin-bottom: 0.52rem;
  a {
    display: block;
  }
  .list-item {
    position: relative;
    height: 1.25rem;
    width: 100%;
    display: flex;
    border-radius: 0.08rem;
    padding: 0.04rem;
    margin-bottom: 0.08rem;
    background: #f2f2f3;
    border: 1px solid #f2f2f3;
    .img-box {
      flex-shrink: 0;
      width: 0.88rem;
      height: 1.17rem;
      border-radius: 0.03rem;
      position: relative;
      overflow: hidden;
      display: block;
      &:hover {
        img {
          transform: scale(1.1);
        }
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: all 0.5s;
      }
    }
    .intro {
      display: flex;
      flex-direction: column;
      width: 120rem;
      justify-content: space-between;
      padding: 0.16rem 0.08rem;
      .title {
        font-size: 0.14rem;
        line-height: 0.2rem;
        color: rgba(0, 0, 0, 0.8);
        font-weight: 500;
        height: 0.4rem;
        width: 1.2rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        word-wrap: break-word;
      }
      .page-num {
        color: rgba(0, 0, 0, 0.4);
        line-height: 0.16rem;
        font-size: 0.14rem;
      }
    }
  }
  .see-more {
    backdrop-filter: blur(8px);
    color: rgba(0, 0, 0, 0.4);
    font-weight: 500;
    height: 1.25rem;
    width: 100%;
    color: rgba(0, 0, 0, 0.4);
    font-weight: 500;
    font-size: 0.16rem;
    padding: 0.04rem;
    margin-bottom: 0.08rem;
    background: #f2f2f3;
    border: 1px solid #f2f2f3;
    cursor: pointer;
    span {
      margin-right: 0.04rem;
    }
  }
}
.tab-box {
  margin-top: 0.32rem;
  margin-bottom: 0.52rem;
  .tab-item {
    height: 0.4rem;
    width: 0.72rem;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    color: hsla(0, 0%, 100%, 0.9);
    font-weight: 500;
    font-size: 0.14rem;
    text-align: center;
    line-height: 0.4rem;
    margin-right: 0.08rem;
    cursor: pointer;
    transition: background-color 0.3s;
  }
  .tab-item:hover,
  .tab-item-activ {
    background-color: #ff375f;
  }
}
@media (max-width: 768px) {
  .breadcrumb-container {
    border: none;
    :deep(.ant-breadcrumb-link),
    a {
      font-size: 0.24rem;
      line-height: 0.24rem;
    }
  }
  .detail-box {
    padding: 0.48rem 0 0.24rem;
    position: relative;
    text-align: center;
    background-color: #fff;
    margin: 0;
    height: auto;
    .book-cover-box {
      height: 3.78rem;
      margin-bottom: 0.32rem;
      text-align: center;
      position: static;
      width: 100%;
      img {
        width: 2.8rem;
        height: 3.78rem;
        border-radius: 0.08rem;
        overflow: hidden;
        margin: 0 auto 0.32rem;
      }
    }
    .book-name {
      font-size: 0.4rem !important;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.9);
      line-height: 0.56rem !important;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      word-wrap: break-word;
      margin-bottom: 0.32rem;
      text-align: center;
    }
    .intro,
    .chapter-count {
      display: none;
    }
    .tag-box {
      margin-bottom: 0.48rem;
      justify-content: center;
      .tag-item {
        font-size: 0.22rem;
        line-height: 0.3rem;
        padding: 0.05rem 0.12rem;
      }
    }
    .play-btn-box {
      position: static;
      // margin-bottom: 0.52rem;
      height: 0.88rem;
      .play-btn {
        margin: 0 auto;
        width: 3.28rem;
        height: 0.88rem;
        background: #f40065;
        font-size: 0.32rem;
        border-radius: 1rem;
        font-weight: 500;
      }
      .share-box {
        display: none;
      }
    }
  }
  .h5-intro-box {
    padding: 0.48rem 0.32rem 0.24rem;
    .intro-title {
      font-size: 0.32rem;
      font-weight: 500;
      line-height: 0.38rem;
      margin-bottom: 0.16rem;
      color: rgba(0, 0, 0, 0.9);
      text-align: left;
    }
    .intro {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3;
      word-wrap: break-word;
      position: relative;
      font-size: 0.28rem;
      font-weight: 400;
      color: rgba(0, 0, 0, 0.6);
      line-height: 0.4rem;
      word-break: break-word;
      text-align: left;
    }
  }
  .episode-nav {
    position: relative;
    margin-bottom: 0.24rem;
    border-top: 0.08rem solid rgba(50, 50, 57, 0.07);
    border-bottom: 0.08rem solid rgba(50, 50, 57, 0.07);
    .catalog-box {
      padding: 0 0.32rem;
      background-color: #fff;
      height: 1rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      p {
        color: rgba(0, 0, 0, 0.9);
        font-size: 0.32rem;
        line-height: 0.38rem;
        margin-right: 0.08rem;
        span {
          font-size: 0.28rem;
          color: rgba(0, 0, 0, 0.6);
          line-height: 0.4rem;
        }
      }
      .anticon {
        color: #9e9e9e;
        font-size: 0.28rem;
      }
    }
    .share-box {
      height: 1rem;
      border-top: 0.08rem solid rgba(50, 50, 57, 0.07);
      background-color: #fff;
      padding-left: 0.32rem;
      display: flex;
      align-items: center;
      .share-label {
        margin-right: 0.2rem;
        color: rgba(0, 0, 0, 0.9);
        font-size: 0.32rem;
      }
      img {
        width: 0.6rem;
        height: 0.6rem;
        border-radius: 50%;
        margin-right: 0.2rem;
        cursor: pointer;
      }
    }
  }
  .title-wrap {
    padding: 0 0 0.16rem;
    h2 {
      font-size: 0.3rem;
      font-weight: 500 !important;
      line-height: 0.48rem;
      color: rgba(0, 0, 0, 0.8);
    }
  }
}
</style>
